<template>
  <!-- 业务查询模块-保单查询列表页面 -->
  <div class="fillcontain">

    <div class="searchPage" v-if="!isSubFlag">
      <!-- 操作按钮 -->
      <!-- 查询表单 -->
      <el-form :model="searchParams" :rules="rules" ref="ruleForm" label-width="120px" class="search_container">
        <el-row class="pb20">
<!--          <el-col :span="6">-->
<!--            <el-form-item label="被保人" prop="uesr">-->
<!--              <el-input clearable v-model="searchParams.uesr" placeholder="被保人"></el-input>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="6">
            <el-form-item label="受理号码" prop="applnum">
              <el-input clearable v-model="searchParams.applnum" placeholder="受理号码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="收款凭证号码" prop="wnotnum">
              <el-input clearable v-model="searchParams.wnotnum" placeholder="收款凭证号码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="保单号码" prop="chdrnum">
              <el-input clearable v-model="searchParams.chdrnum" placeholder="保单号码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="电子投保标识号" prop="serno">
              <el-input clearable v-model="searchParams.serno" placeholder="电子投保标识号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" class="text_center">
            <el-button type="primary" icon="el-icon-search" @click="subGetList"></el-button>
            <el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="contain">
      <!-- 查询结果 -->
      <div class="table_container">
        <el-table
            v-loading="loading"
            :data=" tableData"
            @row-dblclick="goPage"
            highlight-current-row
            header-cell-class-name="table-header-class"
            style="width:100%">
          <el-table-column
              min-width="120"
              property="applnum"
              label="受理号"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="hprrcvdt"
              label="受理日期"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="procflg"
              label="处理状态"
              align='center'
              :formatter="exchange"
              show-overflow-tooltip>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!-- 基本资料页面 -->
    <!--  <baseInfo v-if="isSubFlag" ref="imBaseInfo" :formData.sync="formData" @updatIsSubFlag="updatIsSubFlag" @isSubClose="getIsSubClose"></baseInfo>
-->
    <!-- 弹窗 增加-->
    <el-dialog
        title="增加"
        :visible.sync="addDialogVisible"
        width="30%"
        center>
      <el-row>
        <el-col :span="24" class="mb15">
          <el-col :span="6" class="common-lab">
            <label class="labelName">受理号</label>
          </el-col>
          <el-col :span="14" class="common_info">
            <el-input v-model="addApplnum" placeholder="请输入"></el-input>
          </el-col>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
            <el-button @click="addDialogVisible = false">返 回</el-button>
            <el-button type="primary" @click="addClick">提 交</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
  import {addCheck, getfileInfo, checkReadFiles} from "@/api/policyRecord/materialsMaintain/insurance";
  import constant from '@/utils/constant';
  import TaskConstants, {call} from "@/api/taskManager/common"
  import uwconstant from "@/utils/uwConstants";
  export default {
    components: {
      baseInfo: resolve => require(['../../policyRecord/materialsMaintain/baseInfo.vue'], resolve),
    },
    data() {
      return {
        value: '',
        isSubFlag: false,
        addDialogVisible: false,//弹框
        // 查询条件
        rules: {},
        searchParams: {
          uesr: '', //被保人
          applnum: '', //受理号
          wnotnum: '',//收款凭证号码
          chdrnum: '', //保单号
          serno: '', //电子投保标识号
        },
        formData: null,
        addApplnum: null,
        procflgStatus: '',
        loading: false,
        isShow: true,
        tableData: [],
      }
    },
	activated(){
	    document.onkeydown = (event)=>{
	        var e = event || window.event || arguments.callee.caller.arguments[0];
	        if (e && e.keyCode == 113) {
	            this.subGetList();
	        }
	    };
	}, 
    created() {

    },
    mounted() {
      let applnum = this.$route.query.applnum;
      //let procflgStatus = this.$route.query.procflgStatus;
      if (applnum != undefined && applnum != '' && applnum != null) {
        this.searchParams.applnum = applnum;
        // if(procflgStatus != undefined && procflgStatus != ''
        //      && applnum != procflgStatus){
        //     this.procflgStatus = procflgStatus;
        // }
        this.subGetList();
      }
    },
    methods: {
      goPage(data) {
        let applnum = data.applnum;
        let para = {
          applnum: applnum,
          flag: 'N'
        };
        this.$store.dispatch('loading/CHNAGE_SUBLOADING', true);
        getfileInfo(para).then(res => {
          if (res.resultCode == constant.SUCCESS) {
            this.isShow = false;
            let insureData = res.data;
            console.info("建档资料查询结果", insureData);
            checkReadFiles(para).then(res => {
              if (res.resultCode == constant.SUCCESS) {
                let applnum = res.resultMsg;
                let flag = 'N';
                this.$router.push({path:'/home/policyRecord/baseInfo'+'/'+applnum+'/'+flag,query:{
                    pageSource:'cx'
                }}).catch(data => {});
              }
              this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
            }).catch(err => {
              console.log(err);
              this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
            })
            // this.$router.push({path:'/home/policyRecord/baseInfo'})
          }
          this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
        }).catch(err => {
          console.log(err);
          this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
        })
      },
      exchange: function (row) {
        if (row.procflg == "0") {
          return "受理";
        } else if (row.procflg == "1") {
          return "建档";
        } else if (row.procflg == "2") {
          return "核保";
        } else if (row.procflg == "3") {
          return "照会";
        } else if (row.procflg == "4") {
          return "核决";
        } else if (row.procflg == "5") {
          return "未入账";
        } else if (row.procflg == "6") {
          return "结案";
        }
      },
      // 查询列表
      getfileList() {
        let para = {
          uesr: this.searchParams.uesr,
          applnum: this.searchParams.applnum,
          wnotnum: this.searchParams.wnotnum,
          chdrnum: this.searchParams.chdrnum,
          serno: this.searchParams.serno,
          flag: 'N'
        }
        if (!para.uesr && !para.applnum && !para.wnotnum && !para.chdrnum && !para.serno) {
          this.$message({
            message: '请输入一个查询条件来查询！',
            type: 'error'
          });
          return false;
        }
        this.$store.dispatch('loading/CHNAGE_SUBLOADING', true);
        call(TaskConstants.apis.queryFileList, para, "POST").then(res => {
          if (res.resultCode == constant.SUCCESS) {
            this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
            this.tableData = res.data;
            console.info("保单查询结果", this.tableData);
          } else {
			  this.$confirm("单据不存在，是否需要跳转到euis查询？", '提示', {
			    confirmButtonText: '确定',
			    cancelButtonText: '取消',
			    type: 'warning'
			  }).then(() => {
			    this.callEuis();
			  }).catch(() => {
			  
			  });
		  }
			this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
		  
        }).catch(err => {
          console.log(err);
          this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
        })
      },
	  callEuis(){
		  let username = "";
		  let password = "";
		  if (sessionStorage.getItem("loginForm")) {
		    let loginForm = JSON.parse(sessionStorage.getItem("loginForm"));
		    password = loginForm.password;
		    username = loginForm.userName;
		  }
		  // const url = "http://128.232.9.222:9088/PAS/loginFromIMPL.do?userid="+username+"&password="+password+"&menuid=policyQuery";
		  const url = uwconstant.inquiryurl + "/loginFromIMPL.do?userid=" + username + "&password=" + password + "&menuid=policyQuery";
		  window.open(url);
	  },	  
      // 根据条件查询列表
      subGetList() {
        this.getfileList();
      },
      // 清除查询条件
      resetSearch() {
        this.searchParams.uesr = '';
        this.searchParams.applnum = '';
        this.searchParams.wnotnum = '';
        this.searchParams.chdrnum = '';
        this.searchParams.serno = '';
      },
      updatIsSubFlag(val) {
        this.isSubFlag = val;
      },
      // 监听是否关闭详情页
      getIsSubClose(e) {
        console.log('====:' + e);
        if (e) {
          this.isSubFlag = false;
        } else {
          this.isSubFlag = true;
        }
      }
    },
    watch: {
      $route(to, from) {
        console.log(to);
        console.log(from);
        console.log(this.$route)
      }
    },
  }
</script>

<style lang="less" scoped>
  .fillcontain {
    padding-bottom: 0;
  }

  .contain {
    background: #fff;
    padding: 10px;
    margin-bottom: 20px;
  }

  .pagination {
    padding: 10px 20px;
    text-align: right;
  }

  .operationIcon {
    // padding: 12px;
    border: 1px solid #e5e5e5;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: inline-block;
    cursor: pointer;
    box-shadow: 0 0 3px #f9f9f9;

    .svg-icon {
      font-size: 14px;
      fill: #68a3fc;
    }
  }

  .search_container {
    padding: 20px 20px 0 20px;
  }

  .toView {
    color: #68a3fc;
    cursor: pointer;
  }

</style>



